<!--  -->
<template>
  <div>
    <el-button @click="dialogVisible = true">添加资源</el-button>

    <el-dialog
      title="提示"
      :visible.sync="dialogVisible"
      width="30%"
    >
      <el-form>
        <el-form-item label="资源名">
          <el-input v-model="form.title"></el-input>
        </el-form-item>
        <el-form-item label="简介">
          <el-input v-model="form.code"></el-input>
        </el-form-item>
        <el-form-item label="资源下载地址">
          <el-input v-model="form.download"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="addResources">确 定</el-button>
      </span>
    </el-dialog>

    <el-table :data="tableData" style="width: 100%">
      <el-table-column prop="id" label="编号" width="180"> </el-table-column>
      <el-table-column prop="title" label="资源名" width="180">
      </el-table-column>
      <el-table-column prop="code" label="简介" width="180"> </el-table-column>
      <el-table-column prop="url" label="下载地址"></el-table-column>
    </el-table>
  </div>
</template>

<script>
import axios from "axios";
export default {
  data() {
    return {
      tableData: {},
      dialogVisible: false,
      form:{
        title:"",
        code:"",
        download:""
      }
    };
  },
  methods: {
    getResources() {
      axios.get("http://127.0.0.1:7001/api/resource").then((res) => {
        console.log(res.data.data);
        this.tableData = res.data.data;
      });
    },
    // 添加资源
    addResources() {
      axios.post("http://127.0.0.1:7001/api/resource",{
        form:this.form
      }).then(res =>{
        console.log(res.data);
        location.reload();
      })
    },
  },
  //生命周期 - 创建完成（访问当前this实例）
  created() {
    this.getResources();
  },
  //生命周期 - 挂载完成（访问DOM元素）
  mounted() {},
};
</script>
<style scoped>
/* @import url(); 引入css类 */
</style>